The Feature Set of the ASP.NET API

At this point, your whirlwind review of classic web application development is complete, and you are ready to dive into ASP.NET itself. Before you create your first web application, let me set the stage regarding the major features of .NET’s web development API, as seen from the major versions of the framework.

Major Features of ASP.NET 1.0-1.1

The first release of ASP.NET (version 1.x) contained a number of features that allow developers to build web applications in a strongly typed and object oriented matter. Here are some key features which are supported in all versions of the .NET platform:

The first point I want to elaborate on here is the fact that the UI of an ASP.NET web page is built using any number of web controls. Unlike a typical HTML control, web controls are executed on the web server and will emit back to the HTTP response their correct HTML tags. This alone is a huge benefit of ASP.NET in that the amount of HTML you must manually author by hand diminishes greatly. By way of a quick example, assume you have defined the following ASP.NET web control in an ASP.NET web page:

<asp:Button ID="btnMyButton" runat="server" Text="Button" BorderColor="Blue"
    BorderStyle="Solid" BorderWidth="5px" />

You’ll learn the details of declaring ASP.NET web controls soon enough, but for right now, notice that many attributes of the <asp:Button> control look very similar to the properties you have encountered in the Windows Forms and WPF examples (BorderColor, Text, BorderStyle, etc.). The same is true for all ASP.NET web controls because when Microsoft built the web control toolkit, these widgets were purposely designed to look and feel like their desktop counterparts.

Now, if a browser makes a call to the *.aspx file containing this control, the control responds by emitting into the output stream the following HTML declaration:

<input type="submit" name="btnMyButton" value="Button" id="btnMyButton"
    style="border-color:Blue;border-width:5px;border-style:Solid;" />

Notice how the web control emits back standard HTML (or XHTML, based on your settings) that can be rendered in any browser. Given this, understand that using ASP.NET web controls in no way ties you to the Microsoft family of operating systems or to Microsoft Internet Explorer. Any operating system or browser (including those on handheld devices such as the Apple iPhone or BlackBerry devices) can view an ASP.NET web page.

Next, note from the previous list of features that an ASP.NET web application will be compiled into a .NET assembly. Thus, your web projects are no different than any .NET *.dll built during this book. The compiled web application will be composed of CIL code, an assembly MANIFEST, and type metadata. This has a number of huge benefits, most notably performance gains, strong typing, and the ability to be micromanaged by the CLR (e.g., garbage collection, etc.).

Finally, ASP.NET web applications provide a programming model whereby you can partition your page’s markup from its related C# code base using code files. You’ll learn about this topic in just a bit, but know that this feature addresses a common complaint found when building classic (COM-based) ASP pages, where a typical *.asp file was a confused mismatch of HTML and script code. Using code files, the markup you type will map to a full-blown object model that is merged with your C# code file via partial class declarations.

Major Features of ASP.NET 2.0

ASP.NET 1.x was a major step in the right direction, and ASP.NET 2.0 provided many additional bells and whistles that helped ASP.NET move from a way to build dynamic web pages to a way to build feature rich web sites. Consider this partial list of key features:

Beyond the ASP.NET Development web server, one of the biggest additions brought forth with ASP.NET 2.0 was the introduction of master pages. As you are aware, most web sites have a look and feel which is common to all pages on the site. Consider a commercial web site such as www.amazon.com. Every page has the same elements, such as a common header, common footer, common navigation menus and so on.

Using a master page, you can model this common functionality and define placeholders that other *.aspx files can plug into. This makes it very easy to quickly reshape the overall look and feel of your site (reposition the navigation bar, change the header logo, and so on) by simply changing the master page, leaving the other *.aspx files unmodified.

Note Master pages are so useful that as of Visual Studio 2010, all new ASP.NET web projects will include a master page by default.

ASP.NET 2.0 also added many new web controls into the mix, including controls that automatically incorporate common security features (log in controls, password recovery controls, etc), controls that allow you to layer a navigational structure on top of a set of related *.aspx files, and even more controls for performing complex data binding operations, where the necessary SQL queries could be generated using a set of ASP.NET web controls.

Major Features of ASP.NET 3.5 (and .NET 3.5 SP1)

.NET 3.5 added the ability for ASP.NET web applications to make use of the LINQ programming model (also introduced in .NET 3.5) and the following web-centric features:

One of the most welcomed features in ASP.NET 3.5 was a new set of controls that allow for Ajax development. This web-centric API makes it possible to refresh a small portion of a larger web page in the most efficient manner possible. While Ajax can be used by any web development API, doing so within an ASP.NET site is very simple because the Ajax controls do all of the heavy lifting by emitting back the necessary client side JavaScript code on your behalf.

The ASP.NET Dynamic Data project templates, introduced with .NET 3.5 Service Pack 1, provide a new model to build sites that are driven heavily by a relational database. Of course, most web sites will need to communicate with databases to some extent, but the ASP.NET Dynamic Data projects are tightly connected to the ADO.NET Entity Framework and are squarely focused on the rapid development of data-driven sites (similar to what one might build when using Ruby).

Major Features of ASP.NET 4.0

And this brings me to the web features that ship with the current version of the framework, .NET 4.0. Beyond allowing you to leverage the overall .NET 4.0 features, here is a hit list of some of the key webcentric features:

Note that this list of ASP.NET 1.0-4.0 features is in no way all inclusive, but it does accentuate just how feature-rich this web API truly is. Truth be told, if I were to cover every possible feature of ASP.NET, this book would easily double in size (triple, perhaps). Since this is not realistic, the goal for the remainder of text is to examine the core features of ASP.NET that you will likely use on a day-to-day basis. Be sure to make use of the .NET Framework 4.0 SDK documentation to check out the features not covered here.

Note If you require a comprehensive treatment of building web applications using ASP.NET, I suggest picking up a copy of Pro ASP.NET 4.0 in C# 2010, Third Edition by Matthew MacDonald (Apress, 2010).